<template>
  <div class="login-page">
    <h1>用户管理系统</h1>
    <input type="text" v-model="form.username">
    <input type="text" v-model="form.password">
    <button class="button-default button-primary" @click="handleLogin">登 录</button>
  </div>
</template>

<script>
export default {
  name: 'LoginPage',
  data() {
    return {
      form: {
        username: 'admin',
        password: '123456'
      }
    }
  },
  methods: {
    handleLogin() {
      const {basePath, $axios} = this;
      $axios.post(`${basePath}/admin/login`, {
        ...this.form
      }).then(res => {
        if (res.status === 200 && res.data.reqCode === 0) {
          localStorage.setItem('token', res.data.reqData)
          location.reload()
        } else {
          alert('登陆失败！')
        }
      }).catch(err => {
        console.log(err);
      })
    }
  }
}
</script>

<style scoped>
.login-page {
  display: flex;
  flex-direction: column;
  padding-top: 200px;
}

h1 {
  width: 300px;
  margin: 10px auto;
  font-size: 24px;
  text-align: center;
  font-family: '华文宋体', sans-serif;
}

.login-page input {
  width: 300px;
  margin: 10px auto;
  -webkit-appearance: none;
  background-color: #fff;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  box-sizing: border-box;
  color: #606266;
  display: inline-block;
  font-size: inherit;
  height: 40px;
  line-height: 40px;
  outline: none;
  padding: 0 15px;
  transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
}

.button-default {
  width: 200px;
  margin: 10px auto;
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  background: #fff;
  border: 1px solid #dcdfe6;
  color: #606266;
  -webkit-appearance: none;
  text-align: center;
  box-sizing: border-box;
  outline: none;
  transition: .1s;
  font-weight: 500;
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  padding: 12px 20px;
  font-size: 14px;
  border-radius: 4px;
}

.button-primary {
  color: #fff;
  background-color: #409eff;
  border-color: #409eff;
}

.button-primary:hover {
  background-color: rgba(64, 158, 255, 0.8);
  border-color: rgba(64, 158, 255, 0.8);
}
</style>
